import { defineStore } from 'pinia';
import taskApi from '@/sheep/api/task';
import commissionApi from '@/sheep/api/commission';
import $share from '@/sheep/platform/share';
import { isEmpty, cloneDeep, clone } from 'lodash';
import cart from './cart';
import app from './app';
import { showAuthModal } from '@/sheep/hooks/useModal';

// 默认用户信息
const defaultUserInfo = {
  avatar: '', // 头像
  nickname: '', // 昵称
  gender: 0, // 性别
  mobile: '', // 手机号
  money: '--', // 余额
  commission: '--', // 佣金
  score: '--', // 积分
  verification: {}, // 认证字段
};

// 默认订单、优惠券等其他资产信息
const defaultNumData = {
  coupons_num: '--',
  order_num: {
    aftersale: 0,
    nocomment: 0,
    noget: 0,
    nosend: 0,
    unpaid: 0,
  },
};

const task = defineStore({
  id: 'task',
  state: () => ({
    userInfo: clone(defaultUserInfo), // 用户信息
  }),

  actions: {
    // 获取个人信息
    async getTaskType() {
      const { code, data } = await taskApi.getTaskType();
      if (code !== 1) return;

      console.log('this.userInfo ',data)
      this.userInfo = data;

      return Promise.resolve(data);
    },

  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'task-store',
      },
    ],
  },
});

export default task;
